const oracledb = require('oracledb');

const config = require('./local.secret').oss30Config;
//{ outFormat: oracledb.OUT_FORMAT_OBJECT }
module.exports = function genTableColomnsMeta(tableName) {
    return new Promise(function (rs, rj) {
        oracledb.getConnection(config, function (err, connection) {
            if (err) {
                console.log(err.message);
                return rj(err);
            }
            connection.execute(`select column_name,data_type,data_length from all_tab_cols 
                                 where owner = SYS_CONTEXT('USERENV','CURRENT_USER') 
                                   and table_name='${tableName.toUpperCase()}'`,
              function (err, result) {
                if (err) {
                    console.error(err.message);
                    rj(err);
                } else {
                    // 打印返回的表结构
                    console.log("========" , Object.keys(result), 'metaData', result.metaData,'rows.count',result.rows.length);
                    rs(result.rows)
                }
                connection.close().catch(console.error)
            });
        });
    })
};